package cst.neu.yuejian_31.fragment;


import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cst.neu.yuejian_31.Common.Constant;
import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.activity.ClubDetailActivity;

import static java.lang.System.load;

/**
 * A simple {@link Fragment} subclass.
 */
public class CIntroFragment extends Fragment {
    private View view=null;
    private Context context=null;
    private String clubId,intro,name,pic;
    ;
    private TextView clubName,clubIntro,clubAddress,clubTel;
    private ImageView clubPic;
    private Button btn_Tel;


    public CIntroFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_cintro, container, false);
        clubId=getActivity().getIntent().getStringExtra("club_id");
//        Toast.makeText(getActivity(),clubId, Toast.LENGTH_SHORT).show();
        Intent intent =getActivity().getIntent();
        clubIntro= (TextView) view.findViewById(R.id.textView_club_detail);
        intro=intent.getStringExtra("club_intro");
        clubIntro.setText(intro);

        clubAddress= (TextView) view.findViewById(R.id.textView_club_adress);
        clubAddress.setText(intent.getStringExtra("club_address"));

        clubTel= (TextView) view.findViewById(R.id.textView_club_tel);
        clubTel.setText(intent.getStringExtra("club_phone"));

        btn_Tel= (Button) view.findViewById(R.id.button_tel);
        btn_Tel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//
//                if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
//                    return;
//                }
//                Intent intent =
//                        new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + clubTel.getText().toString()));
//                Intent intent=new Intent();
//                intent.setAction(Intent.ACTION_CALL);
//                Uri data=Uri.parse("tel:" + clubTel.getText().toString());
//                intent.setData(data);
                Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+clubTel.getText().toString()));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        });

//        clubName= (TextView) view.findViewById(R.id.textView_clubname);
//        clubName.setText(intent.getStringExtra("club_name"));


        pic=intent.getStringExtra("club_headpic");
        clubPic= (ImageView) view.findViewById(R.id.imageView_club_detail);
        Picasso.with(getActivity()).load(Constant.CLUB_URL+pic).into(clubPic);


//        ctext= (TextView) view.findViewById(R.id.textView_clubname);
//        ctext.setText(clubName);
        return view;
    }


}
